#ifndef __DIRECTSHOW_H__
#define __DIRECTSHOW_H__
#include "stdafx.h"
#include "dshow.h"
#include "w_qedit.h"
HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum);
HRESULT SelectedDevices(REFGUID category, ULONG nIndex, IMoniker **ppMoniker);
#define DSHOW_ENUM_DEVICES_BEGIN(category)                \
{                                                         \
    IEnumMoniker *pEnum;                                  \
    HRESULT hr = EnumerateDevices(category, &pEnum);      \
    if (SUCCEEDED(hr)) {                                  \
        IMoniker *pMoniker = NULL;                        \
        while (pEnum->Next(1, &pMoniker, NULL) == S_OK) {
#define DSHOW_ENUM_DEVICES_END() \
            pMoniker->Release(); \
        }                        \
        pEnum->Release();        \
    }                            \
}
#define DSHOW_ENUM_DEVICES_GET_INFORMATION(category)                         \
    DSHOW_ENUM_DEVICES_BEGIN(category)                                       \
        IPropertyBag *pPropBag;                                              \
        CVolString szFriendlyName;                                           \
        CVolString szDevicePath;                                             \
        INT nWaveInID = 0;                                                   \
        HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag)); \
        if (SUCCEEDED(hr)) {                                                 \
            VARIANT var;                                                     \
            VariantInit(&var);                                               \
            hr = pPropBag->Read(L"Description", &var, 0);                    \
            if (FAILED(hr)) {                                                \
                hr = pPropBag->Read(L"FriendlyName", &var, 0);               \
            }                                                                \
            if (SUCCEEDED(hr)) {                                             \
                szFriendlyName.SetText(var.bstrVal);                         \
                VariantClear(&var);                                          \
            }                                                                \
            hr = pPropBag->Read(L"DevicePath", &var, 0);                     \
            if (SUCCEEDED(hr)) {                                             \
                szDevicePath.SetText(var.bstrVal);                           \
                VariantClear(&var);                                          \
            }                                                                \
            if(category == CLSID_AudioInputDeviceCategory){                  \
                hr = pPropBag->Read(L"WaveInID", &var, 0);                   \
                if (SUCCEEDED(hr)) {                                         \
                    nWaveInID = var.lVal;                                    \
                    VariantClear(&var);                                      \
                }                                                            \
            }                                                                \
            pPropBag->Release();                                             \
        }                                                                   

#endif